package com.webex.ta.hydra.core.macro;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.webex.ta.hydra.core.Command;
import com.webex.ta.hydra.core.ParamDescriptor;
import com.webex.ta.hydra.core.ParamType;
import com.webex.ta.hydra.gui.macro.MacroIdGenerator;

import java.util.Vector;

/**
 * Created by Cisco WebEx.
 * User: vegaz
 * Date: 2010-9-14
 * Time: 10:30:07
 */
@XStreamAlias("MacroDefinition")
public class MacroDefinition {
    private String name;
    private Vector<ParamDescriptor> fields;
    private Command root;

    public MacroDefinition() {
        this("New Macro " + MacroIdGenerator.getInstance().nextId());
    }

    public MacroDefinition(String name) {
        this.name = name;
        fields = new Vector<ParamDescriptor>();

        createRoot();
    }

    private void createRoot() {
        root = new Command();
        root.setKeyword("GenericController");
        root.setIndent(-1);
    }

    public Vector<ParamDescriptor> getFields() {
        return fields;
    }

    public void setFields(Vector<ParamDescriptor> fields) {
        this.fields = fields;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Command getRoot() {
        return root;
    }

    public void setRoot(Command root) {
        this.root = root;
    }

    public void addField(ParamDescriptor des) {
        fields.add(des);
    }

    public void removeField(int idx) {
        fields.remove(idx);
    }

    public void addStep(Command cmd) {
        root.addChild(cmd);
    }
}
